<?php
class opQues {
	var $id=false;
	var $ques_info=false;
	function __construct() {
		if(!isset($_GET['id'])) js_alert('没有找到该条目信息！',true,HOST_ROOT.'admin/index.php');
		global $user;
		$gm_id=$user->id;
		$id=$_GET['id'];
		$back_time=get_date_time();
		
		$ques_id=$_GET['id'];
		$sql="select gm_id,gm_back from question_info where id=$ques_id";
		$res=sql_get_one($sql,__LINE__);
		$old_gm_back=$res['gm_back'];
		
		if($res['gm_id']==0 && $user->gm_level=='普通GM') {
			$sql="update question_info set gm_id=$gm_id,back1_time='$back_time',solution_flag=2 where id=$ques_id";
			sql_run($sql,__LINE__);
		}
		if(count($_POST)>0) {
			if($user->id!=$res['gm_id'] && $user->gm_level=='普通GM') {
				$error='您没有权限操作该记录!';
				if($user->id!=$res['gm_id']) die($error);
			}
		}
		
		//获取游戏
		$sql="select game_id,server_id from question_info where id=$ques_id";
		$res=sql_get_one($sql,__LINE__);
		$game_id=$res['game_id'];
		$server_id=$res['server_id'];
		$sql="select * from game_type where game_id=$game_id and server_id=$server_id";
		$res=sql_get_one($sql,__LINE__);
		$this->game_name=$res['game_name'];
		$this->server_name=$res['server_name'];
		//end.
		
		//gm回复:	
		if(isset($_POST['gm_reply'])) {
			$back=trim(sql_filter($_POST['reply_content']));
			
			if($_POST['gm_reply']=='质检提交') {
				if(!isset($_POST['c_yes']) && !isset($_POST['c_no'])) js_alert('请选择正确与否!',true);
				
				$use_flag=isset($_POST['c_accept'])?1:0;
				$edit_RP=isset($_POST['c_add_rp'])?intval($_POST['rp_num']):0;
				$check_yes_or_no=isset($_POST['c_yes'])?1:0;
				$back_feel=isset($_POST['c_feel'])?1:0;
				$back_overtime=isset($_POST['c_over_time'])?1:0;
				
				//调整 rp 值
				if($edit_RP!=0) {
					$sql="select user_id from question_info where id=$id";
					$res=sql_get_one($sql,__LINE__);
					$user_id=$res['user_id'];
					$sql="update user_info set RP=RP+$edit_RP where id=$user_id";
					sql_run($sql,__LINE__);
				}
				
				$sql="update question_info set use_flag=$use_flag,edit_RP=$edit_RP,check_yes_or_no=$check_yes_or_no,back_feel=$back_feel,back_overtime=$back_overtime,comment='$back',solution_flag=1,back_check=1 where id=$id";
				sql_run($sql,__LINE__);
			}
							
			if($_POST['gm_reply']=='高级gm提交回复') {
				if($back=='') js_alert('回复内容不能为空',true);
				$sql="update question_info set high_gm_back='$back',high_gm_back_time='$back_time',solution_flag=2,high_gm_id=$gm_id where id=$id";
				sql_run($sql,__LINE__);
				
			}
			if($_POST['gm_reply']=='提交回复') {
				if($back=='') js_alert('回复内容不能为空',true);
				//查看是否需要质检,只有建议或者bug,需要质检
				/*
				$sql="select property from question_class,question_info where question_info.class_id=question_class.class_id and question_info.id=$id";
				$res=sql_get_one($sql,__LINE__);
				if($res['property']=='bug' || $res['property']=='advice') $solution_flag=4;
				else $solution_flag=1;
				*/
				$solution_flag=1;
				$sql="update question_info set gm_back='$back',finish_time='$back_time',solution_flag=$solution_flag ";
				if($old_gm_back!='') $sql.=",gm_back_edit_time='$back_time' ";
				$sql.="where id=$id ";
				sql_run($sql,__LINE__);
			}
			$url=get_self();
			header("location:$url");
		}
		//end
		
		//转高级gm
		if(isset($_POST['to_high_gm'])) {
			$back=trim(sql_filter($_POST['reply_content']));
			$sql="update question_info set gm_explain='$back',solution_flag=3 where id=$id";
			sql_run($sql,__LINE__);
			$url=get_self();
			header("location:$url");
		}
		//end
		
		$sql="select * from question_info where id=$id";
		$res=sql_get_one($sql,__LINE__);
		if(!$res)  js_alert('没有找到该条目信息！',true,HOST_ROOT.'admin/index.php');
		$this->ques_info=$res;
		$this->id=$this->ques_info['id'];
		
		//get user_name
		$user_id=$this->ques_info['user_id'];
		$sql="select nick_name from user_info where id=$user_id";
		$res=sql_get_one($sql,__LINE__);
		
		//get question class
		$this->ques_info['user_name']=$res['nick_name'];
		$class_id=$this->ques_info['class_id'];
		$sql="select * from question_class where class_id=$class_id";
		$res=sql_get_one($sql,__LINE__);
		$this->ques_info['class_1']=$res['title'];
		$parent_id=$res['parent_id'];
		$sql="select title from question_class where class_id=$parent_id";
		$res=sql_get_one($sql,__LINE__);
		$this->ques_info['class_0']=$res['title'];
		
		//get pic
		$ques_id=$this->id;
		$sql="select id from question_pic where question_id=$ques_id";
		$res=sql_get_arr($sql,__LINE__);
		if($res==false) $this->ques_info['pic']['count']=0;
		else {
			$this->ques_info['pic']=$res;
			$this->ques_info['pic']['count']=$res['sql']['count'];
		}

		//get back time
		if($this->ques_info['back1_time']=='') $this->ques_info['back1_time']=get_date_time();
		
		$this->ques_info['replay_flag']='gm处理中..';
		if($this->ques_info['solution_flag']==1) $this->ques_info['replay_flag']='已经解决';
		if($this->ques_info['solution_flag']==3) $this->ques_info['replay_flag']='高级gm处理中..';
		if($this->ques_info['solution_flag']==4) $this->ques_info['replay_flag']='等待质检..';
		
		if($this->ques_info['solution_flag']==3 && $this->ques_info['high_gm_back']=='') $this->wait_high_gm_back=1;
		else $this->wait_high_gm_back=0;
		if(($this->ques_info['solution_flag']==0 || $this->ques_info['solution_flag']==2) && $this->ques_info['high_gm_back']=='') $this->show_to_hign_gm=1;
		else $this->show_to_hign_gm=0;
		
		//get gm name
		if($this->ques_info['gm_id']!=0) {
			$gm_id=$this->ques_info['gm_id'];
			$sql="select gm_name from gm_user where id=$gm_id";
			$res=sql_get_one($sql,__LINE__);
			$this->gm_name=$res['gm_name'];
		}
		if($this->ques_info['high_gm_id']!=0) {
			$high_gm_id=$this->ques_info['high_gm_id'];
			$sql="select gm_name from gm_user where id=$high_gm_id";
			$res=sql_get_one($sql,__LINE__);
			$this->high_gm_name=$res['gm_name'];
		}
	}
}
?>